package com.mihu.stmall.manager.config;

import com.mihu.stmall.manager.interceptor.AdminInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

//用来配置SpringMVC
@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Value("${upload.path}")
    private String path;
    @Autowired
    private AdminInterceptor adminInterceptor;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //添加上传图片的映射路径
        //当客户端访问/upload/路径下的任何资源时，将从本地资源
        registry.addResourceHandler("/upload/**")
                .addResourceLocations("file:"+path);



    }
    //配置拦截器


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册管理员的拦截器
        registry.addInterceptor(adminInterceptor)
                .addPathPatterns("/**")//添加需要拦截的路径
                .excludePathPatterns("/layui/**",
                        "/admin/login.html",
                        "/vercode",
                        "/api/admin/login");//排除不需要拦截的路径
    }
}
